<%@ page language="java" contentType="text/html; charset=utf-8"  
    pageEncoding="utf-8"%>  
<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>火焰比赛系统</title>
		<script src="/match/libs/jquery/3.2.1/jquery-3.2.1.js"></script>
		<link href="/match/css/login/mui.min.css" rel="stylesheet" />
		<link href="/match/css/login/style.css" rel="stylesheet" />
		<script src="/match/libs/tool/md5.js"></script>

	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">登录</h1>
		</header>
		<div class="mui-content">
			<form id='login-form' class="mui-input-group">
				<div class="mui-input-row">
					<label>账号</label>
					<input id='account' type="text" class="mui-input-clear mui-input" placeholder="请输入账号">
				</div>
				<div class="mui-input-row">
					<label>密码</label>
					<input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
				</div>
			</form>
			<div style="color:red;text-align: center;margin-top: 10px;" id="errorTip">&nbsp;</div>
			
			<div class="mui-content-padded">
				<button id='loginButton' class="mui-btn mui-btn-block mui-btn-primary">登录</button>
				<div class="link-area"><a id='reg'>注册账号</a> <span class="spliter">|</span> <a id='forgetPassword'>忘记密码</a>
				</div>
			</div>
			<div class="mui-content-padded oauth-area">

			</div>
		</div>
		<script src="/match/libs/mui/mui.min.js"></script>
		<script src="/match/libs/mui/mui.enterfocus.js"></script>
		<script src="/match/js/login/app.js"></script>
		<script>
		$(function() {
			$("#loginButton").click(function(){
				var phone = $("#account").val();
				var password = $("#password").val();
				if(phone == ""){
					$("#errorTip").html("手机号不能为空");
					return;
				}
				if(password == ""){
					$("#errorTip").html("密码不能为空");
					return;
				}
				password = hex_md5(password);
				$.ajax({ //一个Ajax过程

					type : "post", //以post方式与后台沟通

					url : "/match/user/login", //与此php页面沟通

					dataType : 'json',//返回的值以 JSON方式 解释

					data : "userName="+phone+"&password="+password, //发给php的数据有两项，分别是上面传来的u和p

					success : function(json) {//如果调用php成功		

						var dataObj=eval(json);//转换为json对象

						var type = dataObj.type;
						var status = dataObj.status;
						if(status == "success"){
							window.location = "/match/user/index";
						}else{					
								$("#errorTip").html(dataObj.message);
							
						}
						
					}
				});
			});
		});
		</script>
	</body>

</html>